//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
/*-------------------------------------------------------------------------
 * Filename:      serial.h
 * Version:       $Id: serial.h,v 1.1 2006/10/19 03:20:16 zhangyi Exp $
 * Copyright:     Copyright (C) 1999, Erik Mouw
 * Author:        Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
 * Description:   Header file for serial.c
 * Created at:    Tue Aug 24 20:25:00 1999
 * Modified by:   Erik Mouw <J.A.K.Mouw@its.tudelft.nl>
 * Modified at:   Tue Sep 28 23:43:46 1999
 *-----------------------------------------------------------------------*/
/*
 * serial.h: Serial utilities for blob
 *
 * Copyright (C) 1999 2002  Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#ident "$Id: serial.h,v 1.1 2006/10/19 03:20:16 zhangyi Exp $"

#ifndef BLOB_SERIAL_H
#define BLOB_SERIAL_H

#include <types.h>

typedef enum
{
    baud_1200,
    baud_2400,
    baud_4800,
    baud_9600,
    baud_19200,
    baud_38400,
    baud_57600,
    baud_115200,
    baud_230400,
    baud_COUNT
} serial_baud_t;

typedef int (*serial_init_func_t)(serial_baud_t);
typedef int (*serial_read_func_t)(void);
typedef int (*serial_write_func_t)(int);
typedef int (*serial_poll_func_t)(void);
typedef int (*serial_flush_input_func_t)(void);
typedef int (*serial_flush_output_func_t)(void);

typedef struct
{
    serial_init_func_t init;

    serial_read_func_t read;
    serial_write_func_t write;

    serial_poll_func_t poll;

    serial_flush_input_func_t flush_input;
    serial_flush_output_func_t flush_output;
} serial_driver_t;

/* implemented serial drivers */
extern serial_driver_t s3c2500_serial_driver;
extern serial_driver_t sa11x0_serial_driver;
extern serial_driver_t pxa_serial_driver;
extern serial_driver_t mhn_serial_driver;

/* should be filled out by the architecture dependent files */
extern serial_driver_t *serial_driver;

/* Table of baudrates */
extern const int baud_rates[];

extern void set_GPIO_mode(int);

/* exported functions */
int serial_init(serial_baud_t baudrate);
int serial_read(void);
int serial_write(int c);
int serial_write_raw(int c);
int serial_poll(void);
int serial_flush_input(void);
int serial_flush_output(void);

void SerialOutputString(const char *s);
void SerialOutputHex(const u32 h);
void SerialOutputDec(const u32 d);
void SerialOutputBlock(const char *buf, int bufsize);
void SerialOutputChar (const char c);

int  SerialInputString(char *s, const int len, const int timeout);
int  SerialInputBlock(char *buf, int bufsize, const int timeout);
void SerialOutputRawByte(const char c);
int SerialInputDWordWithTimeout();
unsigned char SerialInputByte();

#endif
